<template>
  <view class="container">
    <!-- 头部 -->
    <uni-nav-bar backgroundColor="rgba(255,22,69,0)" :fixed="true" :statusBar="true" :border="false">
      <block v-slot:left>
        <uni-icons @click="back" class="back" color="#fff" type="back" size="25"></uni-icons>
      </block>
    </uni-nav-bar>
    <view class="header">

      <view class="image">
        <image :src="data.info.shop_head" mode=""></image>
      </view>
      <view class="box">
        <view class="name">
          {{ data.info.name }}
        </view>
        <view class="" style="margin-top: 20upx;display: flex;align-items: center;">
          <uni-rate size="16" :disabled="true" disabledColor="#FFC41F" :value="data.info.star"
                    style="margin-right: 10upx;"/>
          {{ $toFiexd(data.info.star, 1) }}
        </view>
      </view>
      <view @click="shopurl" style="margin-left: 20px;  display: flex;align-items: center;">
        商家后台管理地址
        <uni-icons type="shop" size="20"></uni-icons>

      </view>


    </view>
    <view class="content">
      <view class="box">
        <view class="title">
          总收益
        </view>
        <view class="titles">
          {{ $toFiexd(data.tabel.totalOrderMoney || 0.00, 2) }}
        </view>
        <view class="orderboxs">
          <view class="item">
            <view class="text">支付宝</view>
            <view class="texts">{{ $toFiexd(data.tabel.AlTotalOrderMoney || 0.00, 2) }}</view>
          </view>
          <view class="item">
            <view class="text">微信</view>
            <view class="texts">{{ $toFiexd(data.tabel.WxTotalOrderMoney || 0.00, 2) }}</view>
          </view>
          <view class="item">
            <view class="text">银联</view>
            <view class="texts">{{ $toFiexd(data.tabel.YlTotalOrderMoney || 0.00, 2) }}</view>
          </view>
          <view class="item">
            <view class="text">补贴券</view>
            <view class="texts">{{ $toFiexd(data.tabel.jfTalOrderMoney || 0.00, 2) }}</view>
          </view>
          <view class="item">
            <view class="text">消费券</view>
            <view class="texts">{{ $toFiexd(data.tabel.yeTotalOrderMoney || 0.00, 2) }}</view>
          </view>
          <view class="item">
            <view class="text">扫码</view>
            <view class="texts">{{ $toFiexd(data.tabel.totalScanMoney || 0.00, 2) }}</view>
          </view>
        </view>
      </view>
      <view class="box">
        <view class="orderboxss">
          <view class="titlebox">
            <image src="https://img.fubaozx.cn/static/oldImg/16994991667482.png" mode=""></image>
            财务数据
          </view>
          <view class="moneybox" @click="$goURl('/pages/business/withdrawal')">
            <view class="iitem">
              <image src="https://img.fubaozx.cn/static/oldImg/16994992056629.png" mode=""></image>
              <view class="text">
                可提现积分
              </view>
            </view>
            <view class="iitem">
              <view class="">
                ￥
              </view>
              <view class="text">
                {{ $toFiexd(data.info.money || 0, 2) }}
              </view>
            </view>
          </view>
          <view class="moneybox" style="margin-top: 20upx;"  @click="$goURl(`/pages/business/recordList?wallet_type=3&showNum=${data.info.green}`)">
            <view class="iitem">
              <image src="https://img.fubaozx.cn/static/oldImg/16994992056629.png" mode=""></image>
              <view class="text">
                商家积分
              </view>
            </view>
            <view class="iitem">
              <view class="">
                ￥
              </view>
              <view class="text">
                {{ $toFiexd(data.info.green
                  || 0, 2) }}
              </view>
            </view>
          </view>
          <view class="moneybox" style="margin-top: 20upx;" @click="$goURl(`/pages/business/recordList?wallet_type=2&showNum=${data.info.asset}`)">
            <view class="iitem">
              <image src="https://img.fubaozx.cn/static/oldImg/16994992056629.png" mode=""></image>
              <view class="text">
                资产积分
              </view>
            </view>
            <view class="iitem">
              <view class="">
                ￥
              </view>
              <view class="text">
                {{ $toFiexd(data.info.asset
                  || 0, 2) }}
              </view>
            </view>
          </view>
          <!--					<view class="moneybox" style="margin-top: 30upx;" @click="$goURl('/pages/business/exchange')">-->
          <!--						<view class="iitem">-->
          <!--							<image src="https://img.fubaozx.cn/static/oldImg/16994992056629.png" mode=""></image>-->
          <!--							<view class="text">-->
          <!--								可兑换金额-->
          <!--							</view>-->
          <!--						</view>-->
          <!--						<view class="iitem">-->
          <!--							<view class="">-->
          <!--								￥-->
          <!--							</view>-->
          <!--							<view class="text">-->
          <!--								{{$toFiexd(data.info.money||0,2)}}-->
          <!--							</view>-->
          <!--						</view>-->
          <!--					</view>-->
        </view>
      </view>
      <view class="box">
        <view class="orderboxss">
          <view class="titlebox">
            <image src="https://img.fubaozx.cn/static/oldImg/16994994633541.png" mode=""></image>
            营收分析
          </view>
          <view class="charts-box">
            <qiun-data-charts type="column" :opts="data.opts" :ontouch="true" :chartData="data.tabels"/>
          </view>
        </view>
      </view>
      <view class="box">
        <view class="titleboxs">
          <text class="text">
            基础工具
          </text>
        </view>
        <view class="function flex-wrap">
          <view class="item" @click="$goURl('/pages/business/addGoods')">
            <image src="https://img.fubaozx.cn/static/newImg/icon9.png" mode=""></image>
            <view class="text">
              添加商品
            </view>
          </view>
          <view class="item" @click="$goURl('/pages/business/goodsList')">
            <image src="https://img.fubaozx.cn/static/newImg/icon10.png" mode=""></image>
            <view class="text">
              商品管理
            </view>
          </view>
          <view class="item" @click="$goURl('/pages/business/order')">
            <image src="https://img.fubaozx.cn/static/newImg/icon11.png" mode=""></image>
            <view class="text">
              订单管理
            </view>
          </view>
          <view class="item" @click="$goURl('/pages/business/bank/bank')">
            <image src="https://pili-vod.guanxikeji.com/fubao/img/1757137139294.png" mode=""></image>
            <view class="text">
              银行卡
            </view>
          </view>
          <view class="item"  v-if="data.info&&data.info.code==1&&data.info.state==1" @click="$goURl('/pages/business/QRCode')">
            <image src="https://pili-vod.guanxikeji.com/fubao/img/1757137229343.png" mode=""></image>
            <view class="text">
              二维码
            </view>
          </view>
          <!--					<view class="item" @click="$goURl('/pages/business/missage/missage')">-->
          <!--						<image src="https://img.fubaozx.cn/static/oldImg/16994995664412.png" mode=""></image>-->
          <!--						<view class="text">-->
          <!--							消息通知-->
          <!--						</view>-->
          <!--					</view>-->

        </view>
      </view>
    </view>
    <up-popup v-model:show="showpopup" mode="center" bgColor="transparent">
      <view class="l_f_c_c_c popup_cnt">
        <view class="text_b_32">请选择商家类型</view>
        <view class="text_5_26" @click="$goURl('/pages/business/applyfor?code=0')">供应链</view>
        <view class="text_5_26" @click="$goURl('/pages/business/applyfor?code=1')">本地生活</view>
<!--        <view class="text_5_26" @click="$goURl('/pages/business/Txapplyfor')">本地生活</view>-->
      </view>
    </up-popup>
  </view>

</template>

<script setup>
import {getCurrentInstance, reactive} from "vue";
import {onLoad, onPullDownRefresh, onReachBottom, onShow} from "@dcloudio/uni-app";
import store from '@/store/index.js';

const showpopup = ref(false)
const {
  proxy
} = getCurrentInstance();
const data = reactive({
  info: {},
  tabel: {},
  tabels: {},
  opts: {
    color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
      "#ea7ccc"
    ],
    padding: [15, 15, 0, 5],
    touchMoveLimit: 24,
    enableScroll: true,
    legend: {},
    xAxis: {
      disableGrid: true,
      scrollShow: true,
      itemCount: 2
    },
    yAxis: {
      data: [{
        min: 0
      }]
    },
    extra: {
      column: {
        type: "group",
        width: 190,
        activeBgColor: "#000000",
        activeBgOpacity: 0.08
      }
    }
  }

})
onLoad((option) => {
})
onShow(() => {
  getBusinessToken()
})
onPullDownRefresh(() => {
  setTimeout(function () {
    uni.stopPullDownRefresh();
  }, 1000);
})
onReachBottom(() => {
})

function back() {
  uni.navigateBack()
}

//获取后台地址
function shopurl() {
  uni.setClipboardData({
    data: store.state.baseurl + 'shop/',
    success: function () {
      uni.showToast({
        title: '复制成功',
        icon: 'none',
        duration: 1000
      })
    }
  });

}

function getBusinessToken() { //获取商家token
  proxy.$request({
    url: `api/getBusinessToken/`,
    method: 'get',
    success(res) {
      if (res.errno == 0) {
        uni.setStorageSync('businessToken', res.data.businessToken)
        getSHOP()
        getSHOPexsl()
      } else {

        if (res.errmsg !== "店铺已冻结") {
          // showpopup.value = true
          // uni.showToast({
          //   icon: 'none',
          //   title: res.errmsg
          // })
          uni.redirectTo({
            url:'/pages/business/applyfor?code=0'
          })

        } else {
          proxy.$request({
            url: `api/applyBusiness/`,
            method: "put",
            success(res) {


              console.log(res);
              if (res.errno == 0) {
                uni.showToast({
                  icon: 'none',
                  title: '已申请'
                })
                setTimeout(() => {
                  if (res.data.code == 0) {
                    uni.redirectTo({
                      url: '/pages/business/applyfor?code=0'
                    })
                  } else if (res.data.code == 1) {
                    uni.redirectTo({
                      // url: '/pages/business/Txapplyfor',
                      url: '/pages/business/applyfor?code=1'
                    })
                  }
                }, 1000)


              }
            }
          });
        }
        // setTimeout(() => {
        // 	uni.redirectTo({
        // 		// url: '/pages/business/applyfor'
        // 		url: '/pages/business/Txapplyfor'
        // 	})
        // }, 1000)
      }

    }
  })
}

function getSHOP() { //获取我的店铺信息
  proxy.$SHOPrequest({
    url: `business/modify_info/`,
    method: 'get',
    success(res) {
      data.info = res.data
      uni.setStorageSync('businessID', res.data.ID)
      uni.setStorageSync('businessDetail', res.data)

    }
  })
}

function getSHOPexsl() { //获取数据
  proxy.$SHOPrequest({
    url: `business/analysis/`,
    method: 'get',
    success(res) {
      console.log(res.data, "data")
      const a = {
        "AlOrderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ], //支付宝
        "AlTotalOrderMoney": 0, //支付宝
        "WxOrderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ], //微信
        "WxTotalOrderMoney": 0, //微信
        "YlOrderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ], //银联
        "YlTotalOrderMoney": 0, //银联
        "couponOrderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ], // 补贴券
        "jfTalOrderMoney": 0, //补贴券
        "money": 33.95, //消费券
        "orderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          33
        ], //总额
        "partitionList": [{
          "name": "品牌直销",
          "totalOrderMoney": 33
        },
          {
            "name": "全部",
            "totalOrderMoney": 33
          }
        ],
        "scanList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ], //扫码
        "scanMoney": 0, //扫码收款
        "timeLst": [
          "2025-08-07",
          "2025-08-08",
          "2025-08-09",
          "2025-08-10",
          "2025-08-11",
          "2025-08-12",
          "2025-08-13",
          "2025-08-14",
          "2025-08-15",
          "2025-08-16",
          "2025-08-17",
          "2025-08-18",
          "2025-08-19",
          "2025-08-20",
          "2025-08-21"
        ], //时间
        "totalOrderMoney": 33, //消费券
        "totalScanMoney": 0, //扫码收款
        "yeOrderMoneyList": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          33
        ], //消费券
        "yeTotalOrderMoney": 33, //消费券
      }
      data.tabel = res.data
      let ress = {
        categories: res.data.timeLst.reverse(),
        series: [{
          name: "支付宝",
          data: res.data.AlOrderMoneyList.reverse()
        },
          {
            name: "微信",
            data: res.data.WxOrderMoneyList.reverse()
          },
          {
            name: "银联",
            data: res.data.YlOrderMoneyList.reverse()
          },
          {
            name: "补贴券",
            data: res.data.couponOrderMoneyList.reverse()
          },
          {
            name: "扫码",
            data: res.data.scanList.reverse()
          },
          {
            name: "消费券",
            data: res.data.yeOrderMoneyList.reverse()
          },

          {
            name: "总额",
            data: res.data.orderMoneyList.reverse()
          }
        ]
      };
      data.tabels = JSON.parse(JSON.stringify(ress));
    }
  })
}
</script>

<style lang="scss" scoped>
page {
  // background-color: #fff;
}

.container {
  //background-image: url('https://pili-vod.guanxikeji.com/hemashangcheng/img/1727596994959.jpg');
  background: linear-gradient(180deg, #FFE6C4 50%, #F7F7F7 100%);
  background-repeat: no-repeat;
  background-size: 100% 30vh;
  background-position: top;
  height: 100vh;
  overflow-y: scroll;

  .header {
    padding: 30upx;
    display: flex;

    .image {
      width: 110upx;
      height: 110upx;

      image {
        width: 110upx;
        height: 110upx;
        border-radius: 50%;
      }
    }

    .box {
      //color: #fff;
      margin-left: 20upx;

    }
  }

  .content {
    padding: 30upx;
    // margin-top: 30upx;

    .box {
      padding: 30upx;
      background-color: #fff;
      border-radius: 20upx;
      margin-bottom: 30upx;

      .title {
        font-size: 32upx;
        font-weight: bold;
      }

      .titles {
        font-size: 60upx;
        font-weight: bold;
        margin-top: 20upx;
      }

      .orderbox {
        display: flex;
        margin: 20upx 0;

        .item {
          font-size: 28upx;
          margin-right: 30upx;
          font-weight: 500;

          text {
            font-size: 32upx;
            color: $color1;
            font-weight: bold;
          }
        }
      }

      .orderboxs {
        display: flex;
        margin-top: 60upx;
        flex-wrap: wrap;
        gap: 20rpx 0;

        .item {
          width: 33%;

          .text {
            font-size: 28upx;
            font-weight: 500;
          }

          .texts {
            font-size: 36upx;
            font-weight: bold;
            margin-top: 10upx;
          }
        }
      }

      .orderboxss {
        .titlebox {
          display: flex;
          font-size: 32upx;
          font-weight: bold;
          padding-bottom: 20upx;
          border-bottom: 1upx solid #eee;
          margin-bottom: 20upx;

          image {
            width: 44upx;
            height: 44upx;
            margin-right: 20upx;
          }
        }

        .moneybox {
          background-color: #FFB000;
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 20upx;
          border-radius: 20upx;
          font-size: 28upx;
          color: #fff;

          .iitem {
            display: flex;
            justify-content: space-between;
            align-items: center;

            image {
              width: 36upx;
              height: 36upx;
              margin-right: 10upx;
            }
          }
        }

        .boxlist {
          display: flex;
          text-align: center;
          justify-content: space-between;
          padding: 20upx;

          .item {
            .money {
              font-size: 28upx;
            }

            .moneys {
              color: $color1;
            }

            .text {
              color: #999;
              font-size: 24upx;
              margin-top: 10upx;
            }
          }
        }
      }

      .titleboxs {
        border-bottom: 1upx solid #eee;
        padding-bottom: 20upx;

        .text {
          font-size: 32upx;
          font-weight: bold;
          padding-bottom: 18upx;
          border-bottom: 5upx solid $color1;
        }
      }

      .function {
        display: flex;
        align-items: center;
        // justify-content: space-between;
        text-align: center;
        padding: 20upx 0;

        .item {
          width: 25%;
          margin-top: 20px;

          image {
            width: 64upx;
            height: 64upx;
          }

          .text {
            font-size: 24upx;
            font-weight: bold;
            margin-top: 10upx;
          }
        }
      }
    }
  }
}

.popup_cnt {
  width: 500rpx;
  height: 300rpx;
  border-radius: 30rpx;
  padding: 20rpx;
  background-color: #fff;

  .text_5_26 {
    margin: 20rpx 0 0;
  }
}
</style>
